<template>
    <div class="shopcar-container">
      <div class="mui-card" v-for="item in carList" :key="item.id">
				<div class="mui-card-content">
					<div class="mui-card-content-inner">
            <mt-switch @change="changeSelected(item.id)" v-model="$store.getters.getSelected[item.id]"></mt-switch>
            <img :src="item.thumb_path">
            <div class="info">
              <h1>{{item.title}}</h1>
              <p>
                <span class="price">￥{{item.sell_price}}</span>
                <numberBox :count="$store.getters.getSelectCount[item.id]" :goodsId="item.id"></numberBox>
                <a href="#" @click.prevent="remove(item.id)">删除</a>
              </p>
            </div>
					</div>
				</div>
			</div>
      <div class="mui-card">
				<div class="mui-card-content">
					<div class="mui-card-content-inner jiesuan">
            <div class="left">
              <p>总计(不含运费)</p>
              <p>已勾选商品<span class="red">{{$store.getters.getSelectCountAndAmount.count}}</span>件,总价<span class="red">￥{{$store.getters.getSelectCountAndAmount.price}}</span></p>
  					</div>
            <mt-button type="danger" size="small">去结算</mt-button>
         </div>
				</div>
			</div>
    </div>
</template>
<script>
import numberBox from '../subcomponents/shopCar-numberBox.vue'
export default {
  data(){
    return{
      carList:[],
      flag:false
    }
  },
  created(){
    this.getCarList()
  },
  methods: {
    getCarList(){
      var ids=[]
      this.$store.state.car.forEach(item => {
        ids.push(item.id)
      });
      this.$http.get('api/goods/getshopcarlist/'+ids.join(',')).then(result=>{
        var res=result.body
        if(res.status===0){
          this.carList=res.message
        }
      })
    },
    remove(id){
      this.carList.forEach((item,i) => {
        if(item.id==id){
          this.carList.splice(i,1)
        }
      });
      this.$store.commit('removeFromCar',id)
    },
    changeSelected(id){
      this.$store.commit('changeSelected',id)
    }
  },
  components:{
    numberBox
  }
}
</script>
<style lang="scss" scoped>
   .shopcar-container{
     overflow: hidden;
      .jiesuan{
        display: flex;
        flex-flow: row;
        justify-content: space-between;
        align-items: center;
        .red{
          color:red;
          font-weight: bold;
          font-size: 16px;
        }
      }
     .mui-card-content-inner{
       display:flex;
     }
     img{
       width: 60px;
       height: 60px;
     }
     .info {
      h1{
        font-size: 14px;
        font-weight: bold;
      }
      .price{
        color:red;
        font-weight: bold;
      }
      width: 80%;
      display: flex;
      flex-flow: column;
      justify-content: space-between;
      p{
        display: flex;
        justify-content: space-between
      }     
    }
   } 
</style>